import json

from execelUtil.common import commonUtil as cu

import requests

def delete_redi_key():
    key_prefix = "INV:SALES:RULE:INFO::rule_USTemu"
    keylist = []

    for i in range(1, 51):
        key_str = key_prefix + str(i)
        keylist.append(key_str)
        i += 1
    print(keylist)
    res = cu.deleteKeyRedis(keylist)
    print(res)



## type : value , set , list , hash
def query_stock_redi_key(ruleId, skuCode, type):
    key_prefix = "INV_SALES_STOCK:"+ruleId+":"+skuCode
    params = cu.getApiList(cu.INV_SALE_STOCK_REDIS_KEY_PARA_BODY)
    params[cu.INV_SALE_STOCK_REDIS_KEY_PARA_BODY_PARTTEN] = key_prefix
    params[cu.INV_SALE_STOCK_REDIS_KEY_PARA_BODY_TYPE] = type
    response = requests.post(cu.getApiList(cu.INV_SALE_STOCK_REDIS_KEY_URL), json=params, headers=cu.getHeaders())
    res  = json.loads(response.text)
    print(res)


def query_update_stock_redi_key(type):
    key_prefix = "INV:SALES:STOCK:UPDATE:SKUMAP:INFO"
    params = cu.getApiList(cu.INV_SALE_STOCK_REDIS_KEY_PARA_BODY)
    params[cu.INV_SALE_STOCK_REDIS_KEY_PARA_BODY_PARTTEN] = key_prefix
    params[cu.INV_SALE_STOCK_REDIS_KEY_PARA_BODY_TYPE] = type
    response = requests.post(cu.getApiList(cu.INV_SALE_STOCK_REDIS_KEY_URL), json=params, headers=cu.getHeaders())
    # print(response.text)
    res  = json.loads(response.text)
    print(res)

# query_update_stock_redi_key("hash")

query_stock_redi_key("202407081","FTPLCG-0212","value")